import { ref } from 'vue'
import { useIntersectionObserver } from '@vueuse/core'
export const useLazyData = (apiFn) => {
  const result = ref(null)
  const target = ref(null)
  const { stop } = useIntersectionObserver(target, ([{ isIntersecting }]) => {
    if (isIntersecting) {
      stop()
      apiFn().then(data => {
        result.value = data.result
      })
    }
  })
  return {
    result, target
  }
}
